<template>
	<view class="container">
		<!-- #ifdef MP-WEIXIN -->
		<button class="confirm-btn" open-type="getUserInfo" @getuserinfo="getuserinfo" hover-class="btn-hover">{{contents}}</button>
		<!-- #endif -->
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex';
	export default{
		name: "loginBtn",
		data(){
			return{}
		},
		props: {
			contents: {
				type: String,
				default(){
					return ''
				}
			}
		},
		computed:{
			
		},
		onLoad() {
			
		},
		methods:{
			getuserinfo(e) {
				const that = this
				console.log(e)
				// 拒绝授权
				if(e.detail.errMsg.indexOf('ok') == -1 ){
					uni.showToast({
					    title: '授权后才能体验更多功能哦！',
						icon :'none',
					    duration: 2000
					});
				}else{
					let userInfo = e.detail.userInfo
					uni.setStorage({
						userInfo:userInfo
					})
					
					that.$store.commit('updateUserInfo',userInfo)
					that.$store.commit('changeLogin',true)
					uni.login({
						provider: 'weixin',
						success: (wxres => {
							console.log(wxres)
						})
					})
				}
				
			
			},
		}
	}
</script>

<style lang="scss">
	.confirm-btn{
		display: block;
		width: 100%;
		height: 100%;
		position: absolute;
		left: 0;
		top: 0;
		border: none;
		outline: none;
		background: transparent;
		z-index: 99;
	}
	.confirm-btn::after{
		border: none;
	}
</style>
